<template>
  <div>
    <HomeHeader ></HomeHeader>
    <swiper :swiper="swiperList"></swiper>
    <Icons :list="iconList"></Icons>
    <Recommend :List="recommendList"></Recommend>
    <Weekend :List="weekendList"></Weekend>
  </div>
</template>

<script>
import HomeHeader from './components/Header'
import Swiper from './components/Swoper'
import Icons from './components/Icons'
import Recommend from './components/Recommend'
import Weekend from './components/Weekend'
import {mapState} from "vuex";

import axios from 'axios'

export default {
  name: 'home',
  components: {
    HomeHeader, Swiper, Icons, Recommend, Weekend
  },
  data() {
    return {
      // city: '',
      swiperList: [],
      iconList: [],
      weekendList: [],
      recommendList: [],
      lastCity:''
    }
  },
  computed:{
    ...mapState(['cityL'])
  },
  methods: {
    getHomeInfo() {
      axios.get('/api/index.json?city'+ this.cityL)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc(res) {
      // console.log(res)
      res = res.data
      // console.log(res)
      if (res.ret && res.data) {
        const data = res.data
        // this.city = data.city
        this.swiperList = data.swiperList
        this.iconList = data.iconList
        this.weekendList = data.weekendList
        this.recommendList = data.recommendList

      }
    }
  },
  mounted() {
    this.lastCity = this.cityL
    this.getHomeInfo()
  },
  activated() {
    if(this.lastCity != this.cityL){
      this.lastCity = this.cityL
      this.getHomeInfo()
    }
  }
}
</script>

<style>

</style>
